package com.ruoyi.appreciate.stucomposition.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.appreciate.stucomposition.domain.StudentComposition;
import com.ruoyi.appreciate.stucomposition.service.IStudentCompositionService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生作品Controller
 * 
 * @author duanxinli
 * @date 2025-09-15
 */
@RestController
@RequestMapping("/stucomposition/composition")
public class StudentCompositionController extends BaseController
{
    @Autowired
    private IStudentCompositionService studentCompositionService;

    /**
     * 查询学生作品列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(StudentComposition studentComposition)
    {
        startPage();
        List<StudentComposition> list = studentCompositionService.selectStudentCompositionList(studentComposition);
        return getDataTable(list);
    }

    /**
     * 导出学生作品列表
     */
    @PreAuthorize("@ss.hasPermi('stucomposition:composition:export')")
    @Log(title = "学生作品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentComposition studentComposition)
    {
        List<StudentComposition> list = studentCompositionService.selectStudentCompositionList(studentComposition);
        ExcelUtil<StudentComposition> util = new ExcelUtil<StudentComposition>(StudentComposition.class);
        util.exportExcel(response, list, "学生作品数据");
    }

    /**
     * 获取学生作品详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(studentCompositionService.selectStudentCompositionById(id));
    }

    /**
     * 新增学生作品
     */
    @PreAuthorize("@ss.hasPermi('stucomposition:composition:add')")
    @Log(title = "学生作品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentComposition studentComposition)
    {
        return toAjax(studentCompositionService.insertStudentComposition(studentComposition));
    }

    /**
     * 修改学生作品
     */
    @PreAuthorize("@ss.hasPermi('stucomposition:composition:edit')")
    @Log(title = "学生作品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentComposition studentComposition)
    {
        return toAjax(studentCompositionService.updateStudentComposition(studentComposition));
    }

    /**
     * 删除学生作品
     */
    @PreAuthorize("@ss.hasPermi('stucomposition:composition:remove')")
    @Log(title = "学生作品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(studentCompositionService.deleteStudentCompositionByIds(ids));
    }
}
